import Data.List
import Data.Ord

decimalSequence :: Integer -> [(Integer,Integer)] -> [(Integer,Integer)]
decimalSequence n [] 		= decimalSequence n [(10 `div` n, 10 `rem` n)]
decimalSequence n xs
	| remainder == 0		= xs
	| remainderSeenBefore 	= xs ++ [(newDigit,newRemainder)]
	| otherwise 			= decimalSequence n (xs ++ [(newDigit, newRemainder)])
	where
		digit = (fst.last) xs
		remainder = (snd.last) xs
		newDigit = (remainder * 10) `div` n
		newRemainder = (remainder * 10) `rem` n
		remainderSeenBefore = ((find ((==newRemainder).snd) xs) /= Nothing )
		
recuringSection :: [(Integer,Integer)] -> [(Integer,Integer)]
recuringSection (x:xs)
	| snd x == 0 	= []
	| otherwise 	= x : takeWhile (/=x) (xs)

listOfLengths = map (length.recuringSection.(\x -> decimalSequence x [])) [1..1000]
euler_026 = maximumBy (comparing snd) $ zip [1..1000] listOfLengths